package org.orz.story.member.client;

import cn.hutool.core.collection.CollUtil;
import org.orz.cloud.common.exception.BusinessException;
import org.orz.cloud.common.result.ResultDTO;
import org.orz.story.pms.api.PmsAccountClient;
import org.orz.story.pms.api.WorkbenchClient;
import org.orz.story.pms.api.enums.WorkbenchCodeEnum;
import org.orz.story.pms.api.model.dto.AccountWorkbenchListDto;
import org.orz.story.pms.api.model.dto.CreatePmsAccountReq;
import org.orz.story.pms.api.model.vo.AccountWorkbenchListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class PmsClient {
    @Autowired
    private WorkbenchClient workbenchClient;
    @Autowired
    private PmsAccountClient pmsAccountClient;

    /**
     * 查询账户工作台列表
     */
    public List<AccountWorkbenchListVo> getAccountWorkbenchList(Long accountId){
        AccountWorkbenchListDto dto = new AccountWorkbenchListDto();
        dto.setAccountId(accountId);
        ResultDTO<List<AccountWorkbenchListVo>> result = workbenchClient.getAccountWorkbenchList(dto);
        if(!result.getSuccess()){
            throw new BusinessException(result.getCode(), result.getMessage());
        }
        return result.getData();
    }

    /**
     * 创建权限账号
     * @param memAccountId 用户账号id
     */
    public void createPmsAccount(Long memAccountId, WorkbenchCodeEnum workbenchCodeEnum){
        CreatePmsAccountReq req = new CreatePmsAccountReq();
        req.setMemAccountId(memAccountId);
        req.setWorkbenchCode(CollUtil.newArrayList(workbenchCodeEnum));
        ResultDTO<Boolean> result = pmsAccountClient.createPmsAccount(req);
        if(!result.getSuccess()){
            throw new BusinessException(result.getCode(), result.getMessage());
        }
    }


}
